<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>CartList</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <!-- shop cart -->
    <link rel="stylesheet" href="<%=request.getContextPath() %>/resources/css/cart/shopcart.css" type="text/css" media="all" />
    <script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/cart/shopcart.js"></script>

    <script type="application/javascript">
        function doExport() {
//            var jiesuan = document.getElementById('close').getAttribute("disabled");
                var cartTable = document.getElementById('cartTable');
                var tr = cartTable.children[1].rows;
                for (var i = 0; i < tr.length; i++) {
                    var input = document.getElementsByName('quantity')[i];
                    var input1 = document.getElementsByName('quantity1')[i];
                    input1.value=input.getAttribute("ref")+":"+input.value;
                }
                //价格总和
                var total= document.getElementById('priceTotal').innerHTML;
                var input2 = document.getElementsByName('totalMoney')[0];
                input2.value = total;
                document.getElementById("CartForm").action="<%=request.getContextPath()%>/cart/userToPay";
                document.getElementById("CartForm").submit();
        }
        function doDel() {
            document.getElementById("CartForm").action="<%=request.getContextPath()%>/cart/userCartDelChecked";
            document.getElementById("CartForm").submit();
        }

    </script>
</head>
<body>
<div id="container">
    <%@include file="/jsp/public/top.jspf"%>
    <div id="mainbody">
        <div class="wrap"  align="center">
            <br><br>
            <form method="post" id="CartForm" style="width:80%">
            <table id="cartTable"  >
                <thead>
                <tr>
                    <th><label><input class="check-all check" type="checkbox" />&nbsp;全选</label></th>
                    <th>商品信息</th>
                    <th>单价（元）</th>
                    <th>数量</th>
                    <th>小计（元）</th>
                    <th>操作</th>
                </tr>
                </thead>
                    <tbody>
                <%--遍历用户购物记录--%>
                <c:forEach items="${cartList.datas}" var="cart" >
                <tr>
                    <td class="checkbox">
                       <%-- name="ids" value=${cart.id}--%>
                      <input type="checkbox"  class="check-one check" name="ids" value="${cart.id}"/>
                    </td>
                    <td>
                        <img src="<%=request.getContextPath() %>/resources/images/goodsImages/${cart.goods.image}" alt=""/>
                        <h5><a herf="#"/>商品名:${cart.goods.name}</h5></a><br>
                        <h5 class="alise">CPU:${cart.goods.CPU}RAM:${cart.goods.RAM} HD:${cart.goods.HD}</h5>
                   </td>
                    <td class="price">${cart.goods.price}</td>
                    <td class="count">
                        <span class="reduce">-</span>
                        <%-- <input class="count-input" type="text" value="1"/>--%>
                        <%-- 从添加购物车成功的页面用户先已确定的数量和总价--%>

                    <input class="count-input" name="quantity" id="quantity"  ref="${cart.id}" value="${cart.quantity}"/>
                        <input type="hidden" name="quantity1" value="">
                        <input type="hidden" id="stock" value="${cart.goods.stock}"/>
                    <span class="add">+</span></td>
                    <td class="subtotal">${cart.subtotal}</td>
                    <td class="operation"><a href="${cart.id }/delete" class="delete"  oper="delete">删除</a></td>
                </tr>
                </c:forEach>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="8">
                        <jsp:include page="/jsp/public/pager.jsp">
                            <jsp:param value="${cartList.total }" name="totalRecord"/>
                            <jsp:param value="userCartList" name="url"/>
                        </jsp:include>
                    </td>
                </tr>
                </tfoot>
            </table>
                <input type="hidden" name="totalMoney" value="">
            <div class="foot" id="foot">
                <label class="fl select-all"> <input type="button" class="f1 delete" id="deleteAll"  onclick="doDel()" value="删除" ></label>
                <div class="fr closing">
                    <input  type="button" value="结 算" id="close" disabled="disabled" onclick="doExport()">
                </div>
                <div class="fr total">合计：￥<span id="priceTotal">0.00</span></div>
                <div class="fr selected" id="selected">已选商品
                    <span id="selectedTotal">0</span>件
                    <span class="arrow up">︽</span>
                    <span class="arrow down">︾</span>
                </div>
                <div class="selected-view">
                    <div id="selectedViewList" class="clearfix">
                    </div>
                    <span class="arrow">◆<span>◆</span></span>
                </div>
            </div>
            </form>
        </div>
    </div>
</div>
<div class="footPush"></div>
<%@include file="/jsp/public/footer.jspf"%>
</body>
</html>
